package com.xbongbong.sys.enums;

import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 模型枚举
 * 创建时间 2021/5/26 9:20 AM
 * 修改时间 2021/5/26 9:20 AM
 * @author chy
 */
@Getter
public enum DdModelEnum {
    /**
     * 钉钉标准客户模型
     */
    STANDARD_CUSTOMER_MODEL("EM-10149F1C9A6D0B1738B30000","standardCustomerModel", "钉钉标准客户模型", XbbRefTypeEnum.CUSTOMER),
    /**
     * 钉钉标准合同模型
     */
    STANDARD_CONTRACT_MODEL("EM-10149F1C2FAC0B1738B3000Z","standardContractModel", "钉钉标准合同模型", XbbRefTypeEnum.CONTRACT),
    /**
     * 钉钉标准销售机会模型
     */
    STANDARD_OPPORTUNITY_MODEL("EM-10162CE2C1C80B01B8D0000B","standardOpportunityModel", "钉钉标准销售机会模型", XbbRefTypeEnum.SALES_OPPORTUNITY),
    /**
     * 钉钉标准产品模型
     */
    STANDARD_PRODUCT_MODEL("EM-10149F1A986F0B1738B3000H","standardProductModel", "钉钉标准产品模型", XbbRefTypeEnum.PRODUCT),
    /**
     * 钉钉标准产品分类模型
     */
    STANDARD_PRODUCT_CATEGORY_MODEL("EM-10149F1CC73D0B1738B30000","standardProductCategoryModel", "钉钉标准产品分类模型", XbbRefTypeEnum.PRODUCT_CATEGORY),
    /**
     * 钉钉标准仓库模型
     */
    STANDARD_WAREHOUSE_MODEL("EM-10149F1ACDF40B1738B3000R","standardWarehouseModel", "钉钉标准仓库模型", XbbRefTypeEnum.WAREHOUSE),
    /**
     * 钉钉标准回款计划模型
     */
    STANDARD_PAYMENT_MODEL("EM-101521C4B57C0B01B8D0000H","standardPaymentModel", "钉钉标准回款计划模型", XbbRefTypeEnum.PAYMENT),
    /**
     * 钉钉标准收款单模型
     */
    STANDARD_PAYMENT_SHEET_MODEL("EM-10149F1A4D2D0B1738B3000R","standardPaymentSheetModel", "钉钉标准收款单模型", XbbRefTypeEnum.PAYMENT_SHEET),
    /**
     * 钉钉官方报销单模型
     */
    STANDARD_REIMBURSEMENT_MODEL("EM-1015C5931F740B081F4F000F","standardReimbursementModel", "钉钉官方报销单模型", XbbRefTypeEnum.REIMBURSEMENT_FORM),
    /**
     * UNKNOWN
     */
    UNKNOWN("unknown","unknown", "未知模型触发器id", XbbRefTypeEnum.UNKNOWN),
    ;

    /** 枚举值 -- */
    private final String modelId;
    /** 枚举描述 --英文名称*/
    private final String alias;
    /** 枚举信息--中文名称 */
    private final String name;
    private final XbbRefTypeEnum xbbRefTypeEnum;

    DdModelEnum(String modelId, String alias, String name, XbbRefTypeEnum xbbRefTypeEnum) {
        this.modelId = modelId;
        this.alias = alias;
        this.name = name;
        this.xbbRefTypeEnum = xbbRefTypeEnum;
    }

    /**
     * 获取全部枚举
     *
     * @return List<BossModelEnum>
     */
    public static List<DdModelEnum> getAllEnum() {
        List<DdModelEnum> list = new ArrayList<>();
        for (DdModelEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }

    /**
     * 根据code获取枚举
     * @return
     */
    public static DdModelEnum getByModelId(String modelId) {
        if (modelId == null) {
            return UNKNOWN;
        }
        for (DdModelEnum cache : values()) {
            if (Objects.equals(cache.getModelId(), modelId)) {
                return cache;
            }
        }
        return UNKNOWN;
    }

    public String getName() {
        return name;
    }

    /**
     * 根据业务类型获取模型id
     * @return
     */
    public static List<String> getModelId(XbbRefTypeEnum xbbRefTypeEnum) {
        List<String> modelIdList = new ArrayList<>();
        switch (xbbRefTypeEnum) {
            case CUSTOMER:
                modelIdList.add(STANDARD_CUSTOMER_MODEL.getModelId());
                break;
            case CONTRACT:
                modelIdList.add(STANDARD_CONTRACT_MODEL.getModelId());
                break;
            case SALES_OPPORTUNITY:
                modelIdList.add(STANDARD_OPPORTUNITY_MODEL.getModelId());
                break;
            case PRODUCT:
                modelIdList.add(STANDARD_PRODUCT_MODEL.getModelId());
                break;
            case PRODUCT_CATEGORY:
                modelIdList.add(STANDARD_PRODUCT_CATEGORY_MODEL.getModelId());
                break;
            case WAREHOUSE:
                modelIdList.add(STANDARD_WAREHOUSE_MODEL.getModelId());
                break;
            case PAYMENT:
                modelIdList.add(STANDARD_PAYMENT_MODEL.getModelId());
                break;
            case PAYMENT_SHEET:
                modelIdList.add(STANDARD_PAYMENT_SHEET_MODEL.getModelId());
                break;
            default :
                break;
        }
        return modelIdList;
    }

    /**
     * 根据业务类型获取钉钉标准模型id
     * @return
     */
    public static String getStandardModelId(XbbRefTypeEnum xbbRefTypeEnum) {
        String modelId = null;
        switch (xbbRefTypeEnum) {
            case CUSTOMER:
                modelId = STANDARD_CUSTOMER_MODEL.getModelId();
                break;
            case CONTRACT:
                modelId = STANDARD_CONTRACT_MODEL.getModelId();
                break;
            case SALES_OPPORTUNITY:
                modelId = STANDARD_OPPORTUNITY_MODEL.getModelId();
                break;
            case PRODUCT:
                modelId = STANDARD_PRODUCT_MODEL.getModelId();
                break;
            case PRODUCT_CATEGORY:
                modelId = STANDARD_PRODUCT_CATEGORY_MODEL.getModelId();
                break;
            case WAREHOUSE:
                modelId = STANDARD_WAREHOUSE_MODEL.getModelId();
                break;
            case PAYMENT:
                modelId = STANDARD_PAYMENT_MODEL.getModelId();
                break;
            case PAYMENT_SHEET:
                modelId = STANDARD_PAYMENT_SHEET_MODEL.getModelId();
                break;
            default :
                break;

        }
        return modelId;
    }
}
